package com.cdut.logistics.model.dao.businesses;


import java.util.Date;
import java.util.List;

import com.cdut.logistics.config.Constants;
import com.cdut.logistics.model.entity.Model.News;

public class NewsDao {
	public static NewsDao dao = new NewsDao();
	/**
	 * 
	 * @param title
	 * @param url
	 * @param content
	 * @param img_id
	 * @param video_url
	 * @param sort
	 * @return
	 */
	public boolean news_create(String title,String url,String content,String img_id,String video_url,int sort)
	{
		News news = new News();
		news.set("title", title);
		news.set("url", url);
		news.set("content", content);
		news.set("img_id", img_id);
		news.set("video_url", video_url);
		news.set("sort", sort);
		news.set("is_use", 1);
		news.set("active", 1);
		news.set("created", new Date());
		
		boolean is_success = news.save();
		return is_success;
	}
	
	public List<News> news_search()
	{
		String sql ="select * from News where " +Constants.sql_add;
		List<News> list = News.dao.find(sql);
		return list;
	}
	/**
	 * 
	 * @param news_id
	 * @return
	 */
	public News news_search(int news_id)
	{
		String sql ="select * from News where id = ? and " +Constants.sql_add;
		News news = News.dao.findFirst(sql,news_id);
		return news;
	}
	public boolean news_update(int news_id,String title,String url,String content,String img_id,String video_url,int sort)
	{
		News news = News.dao.findById(news_id);
		news.set("title", title);
		news.set("url", url);
		news.set("content", content);
		news.set("img_id", img_id);
		news.set("video_url", video_url);
		news.set("sort", sort);
		news.set("is_use", 1);
		news.set("active", 1);
		news.set("updated", new Date());
		boolean is_success = news.update();
		return is_success;
	}
	public boolean news_delete(int news_id)
	{
		String sql ="select * from News where id = ? and " +Constants.sql_add;
		News news = News.dao.findFirst(sql,news_id);
		news.set("is_use", 0);
		boolean is_success= news.update();
		return is_success;
	}
}
